import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:winkai/entity/role_info.dart';
import 'package:winkai/res/app_colors.dart';
import 'package:winkai/res/dimens.dart';
import 'package:winkai/ui/user/controller/user_details_controller.dart';
import 'package:winkai/ui/user/widget/user_details_action_widget.dart';
import 'package:winkai/ui/user/widget/user_details_info_widget.dart';
import 'package:winkai/ui/user/widget/user_details_title_bar.dart';
import 'package:winkai/utils/image_utils.dart';
import 'package:winkai/widget/custom_style_bg.dart';
import 'package:winkai/widget/normal_action_widget.dart';

class UserDetailsPage extends StatefulWidget {
  const UserDetailsPage({super.key});

  @override
  State<UserDetailsPage> createState() => _UserDetailsPageState();
}

class _UserDetailsPageState extends State<UserDetailsPage> {
  late String tag;

  late UserDetailsController controller;

  @override
  void initState() {
    super.initState();
    var args = Get.arguments;
    String sessionId = args['sessionId'];
    RoleInfo roleInfo = args['roleInfo'];
    tag = 'UserDetailsController-$sessionId';
    controller = Get.put(
      UserDetailsController(sessionId, roleInfo),
      tag: tag,
    );
  }

  @override
  void dispose() {
    Get.delete<UserDetailsController>(tag: tag, force: true);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GetBuilder<UserDetailsController>(
          tag: tag,
          builder: (_) {
            return AnnotatedRegion<SystemUiOverlayStyle>(
              value: SystemUiOverlayStyle.light,
              child: Stack(
                children: [
                  Column(
                    children: [
                      UserDetailsInfoWidget(roleInfo: controller.roleInfo),
                      UserDetailsActionWidget(controller: controller)
                    ],
                  ),
                  const UserDetailsTitleBar(),
                ],
              ),
            );
          }),
    );
  }
}
